package com.wangcanxuan.www.entity.dto;

import static com.wangcanxuan.www.entity.dto.ResultConstants.*;

/**
 * 封装返回结果的类
 *  状态码成功为200，失败为403
 *  提示信息
 *  返回对象 （字符串，实体类、集体等）
 *
 * @author HHLJ
 * @date 2022/03/26
 */
public class ResultInfo<T> {
    /**
     * 返回给swing的语句，假如用户名为空，登陆成功那些
     */
    private String message;

    /**
     * 根据状态码，给swing做条件判断
     */
    private Integer code;

    /**
     * 传给swing的实体类对象
     */
    private T obj;

    public static <P> ResultInfo<P> operateRejectWithMessage(String message) {
        return new ResultInfo<>(message,REJECT_REQUEST_CODE.getCode());
    }

    public boolean isSuccess() {
          return this.code.equals(SUCCESS_REQUEST_CODE.getCode());
    }

    public ResultInfo() {
    }

    public ResultInfo(T obj) {
        this.obj = obj;
    }

    public ResultInfo(Integer code) {
        this.code = code;
    }

    public ResultInfo(int code, T obj) {
        this.code = code;
        this.obj = obj;
    }

    public ResultInfo(String message, int code) {
        this.message = message;
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public int getCode() {
        return code;
    }

    public T getObj() {
        return obj;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setObj(T obj) {
        this.obj = obj;
    }
}
